<?php
/**
 * List Iterator
 *
 * @version $Id: IListIterator.php 312 2008-04-23 16:29:38Z iwind $
 * @package util.collection
 * @since 0.0.2
 */
class IListIterator extends IObject implements Iterator {
	private $currentIndex = 0;
	private $size;
	private $array;
	
	/**
	 * 构造器
	 *
	 * @param array $array 用来做容器的数组
	 */	
	public function __construct(array & $array) {
		$this->array = $array;
		$this->size = count($array);
	}
	
	/**
	 * 取得当前位置的值
	 *
	 * @return mixed
	 */	
	public function current() {
	 	return $this->array[$this->currentIndex];
	}
	 
	/**
	 * 取得当前位置的键
	 *
	 * @return mixed
	 */	
	public function key() {
		return $this->currentIndex;
	}
	
	/**
	 * 向下移动指针
	 *
	 */	
	public function next() {
		$this->currentIndex += 1;
	}
	
	/**
	 * 将指针移至初始位置
	 *
	 */	
	public function rewind() {
		$this->currentIndex = 0;
	}
	
	/**
	 * 检查当前位置是否有效
	 *
	 * @return boolean
	 */	
	public function valid() {
		return $this->currentIndex < $this->size;
	}
}

?>